package engine;

public class RS {
	public RSEntry[] entries;
	int noAdd;
	int noMult;
	//int noDiv;
	int noLoad;
	int noStore;
	int n;
	public RS(int noAdd,int noMult,int noLoad,int noStore,int n) throws Exception {
		this.noAdd=noAdd;
		//this.noDiv=noDiv;
		this.noLoad=noLoad;
		this.noStore=noStore;
		this.noMult=noMult;
		this.n=n;
		if(noAdd+noLoad+noStore+noMult!=n) {
			throw new Exception("No of reservation stations does not match summation of units you stated!");
		}
		entries=new RSEntry[n];
		initializeRS();
	}
	public void initializeRS() {
		int index=0;
		int tempAdds=0;
		while(tempAdds<noAdd) {
			RSEntry temp=new RSEntry("ADD"+(tempAdds+1));
			temp.type=3;
			entries[index]=temp;
			index++;
			tempAdds++;
		}
		int tempStores=0;
		while(tempStores<noStore) {
			RSEntry temp=new RSEntry("STORE"+(tempStores+1));
			temp.type=2;
			entries[index]=temp;
			index++;
			tempStores++;
		}
		int tempLoads=0;
		while(tempLoads<noLoad) {
			RSEntry temp=new RSEntry("LOAD"+(tempLoads+1));
			temp.type=1;
			entries[index]=temp;
			index++;
			tempLoads++;
		}
		int tempMults=0;
		while(tempMults<noMult) {
			RSEntry temp=new RSEntry("MULT"+(tempMults+1));
			temp.type=4;
			entries[index]=temp;
			index++;
			tempMults++;
		}
	}
	public void clearRSEntry(int i) {
		entries[i].clearRS();
	}
	
}
